"""
--------------------------------------------------------
@File             : EdgeGateCommuChannel.py
@Creat Time       : 2021-01-31
@Author           : wangzp
@Site             :
@Software         : PyCharm
@file Conent      :
--------------------------------------------------------
@Revise history   :
@Version          : V12
@Amendant records :
     1)wangzp  2021-01-31
"""


import EdgeGateData
import time
# 用于发送信息 参数：(ID，socket对象，ip和端口号的元组)
def MsgSend(id,AcceptSocket,addr):
    while True:
        # 判断连接状态
        if EdgeGateData.gConnectedStateDictionary[addr] == 0:
            break
        time.sleep(2)
        try:
            # 发送信息
            AcceptSocket.send(EdgeGateData.gSocketSendData.encode('utf-8'))
            print("正向{0}发送了一条数据{1}".format(addr,EdgeGateData.gSocketSendData))
        except Exception as e:
            print("发送线程：发送失败，{0}连接已断开，{1}".format(addr, e))
            # 重置连接状态为断开（0）
            EdgeGateData.gConnectedStateDictionary[addr] = 0
            AcceptSocket.close()
            pass